package spe.ui.editor;

import org.eclipse.gef.ContextMenuProvider;
import org.eclipse.gef.EditPartViewer;
import org.eclipse.gef.ui.actions.ActionRegistry;
import org.eclipse.gef.ui.actions.GEFActionConstants;
import org.eclipse.jface.action.IAction;
import org.eclipse.jface.action.IMenuManager;
import org.eclipse.ui.actions.ActionFactory;

import spe.ui.action.CancelableDeleteAction;
import spe.ui.action.PropertiesAction;
import spe.ui.action.PropertiesSelectionAction;


public class GraphicalViewerContextMenuProvider extends ContextMenuProvider 
{
	private ActionRegistry actionRegistry;
	
	public void setActionRegistry(final ActionRegistry ar)
	{
		this.actionRegistry = ar;
	}
	
	public ActionRegistry getActionRegistry()
	{
		return actionRegistry;
	}

	public GraphicalViewerContextMenuProvider(EditPartViewer viewer, final ActionRegistry ar)
	{
		super(viewer);
		this.actionRegistry = ar;
		// TODO Auto-generated constructor stub
		
	}

	@Override
	public void buildContextMenu(IMenuManager mnmg)
	{
		GEFActionConstants.addStandardActionGroups(mnmg);
		IAction action;
		
		/*
		action = actionRegistry.getAction(ActionFactory.UNDO.getId());
		mnmg.appendToGroup(GEFActionConstants.GROUP_UNDO, action);
		
		action = actionRegistry.getAction(ActionFactory.REDO.getId());
		mnmg.appendToGroup(GEFActionConstants.GROUP_UNDO, action);
		*/
		action = actionRegistry.getAction(ActionFactory.DELETE.getId());
		if(action.isEnabled())
			mnmg.appendToGroup(GEFActionConstants.GROUP_EDIT, action);
		
		action = actionRegistry.getAction(PropertiesSelectionAction.ID);
		mnmg.appendToGroup(GEFActionConstants.GROUP_VIEW, action);
		
		action = actionRegistry.getAction(CancelableDeleteAction.ID);
		mnmg.appendToGroup(GEFActionConstants.GROUP_EDIT, action);
		
	}

}
